package com.spring;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class JedisZset {

    public static void test1(Jedis jedis) {
        System.out.println("zadd 和 zrange 的使用");
        jedis.flushAll();

        jedis.zadd("key1",10,"zhangsan");
        jedis.zadd("key1",20,"lisi");
        jedis.zadd("key1",30,"wangwu");

        List<String> key1 = jedis.zrange("key1", 0, -1);
        System.out.println(key1);
    }

    public static void test2(Jedis jedis) {
        System.out.println("zcard 和 zrem 的使用");
        jedis.flushAll();

        jedis.zadd("key1",10,"zhangsan");
        jedis.zadd("key1",20,"lisi");
        jedis.zadd("key1",30,"wangwu");

        long key1 = jedis.zcard("key1");
        System.out.println(key1);

        long zrem = jedis.zrem("key1", "zhangsan");
        System.out.println(zrem);

        key1 = jedis.zcard("key1");
        System.out.println(key1);
    }

    public static void test3(Jedis jedis) {
        System.out.println("zscore 和 zrank 的使用");
        jedis.flushAll();

        jedis.zadd("key1",10,"zhangsan");
        jedis.zadd("key1",20,"lisi");
        jedis.zadd("key1",30,"wangwu");


        Double zscore = jedis.zscore("key1", "zhangsan");
        System.out.println(zscore);

        Long zrank = jedis.zrank("key1", "zhangsan");
        System.out.println(zrank);
    }

    public static void main(String[] args) {
        JedisPool jedispool=new JedisPool("tcp://127.0.0.1:8888");

        try(Jedis jedis=jedispool.getResource()){
            jedis.auth("123456");
//            test1(jedis);
//            test2(jedis);
            test3(jedis);
        }
    }
}
